/*
 * @(#)EmailReceiver.java 
 *
 * Copyright (c) 2005 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

package com.dcivision.mail.core;

import java.util.Iterator;
import java.util.List;

import javax.mail.Message;
import javax.servlet.http.HttpServletRequest;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.TextUtility;
import com.dcivision.mail.bean.EmailFolder;
import com.dcivision.mail.bean.EmailMessage;
import com.dcivision.mail.bean.EmailMessageImpl;

/**
 EmailReceiver.java

 This class about receive email.

 @author      Beyond.Qu
 @company     DCIVision Limited
 @creation date   14/01/2005
 @version     $Revision: 1.22.2.1 $
 */

public abstract class EmailReceiver  {

  public static String SORT_ASC = "ASC";
  public static String SORT_DSC = "DSC";    

  public final static int PRIORITY_HIGHEST = 5;
  public final static int PRIORITY_HIGH = 4;
  public final static int PRIORITY_NORMAL = 3;
  public final static int PRIORITY_LOW = 2;
  public final static int PRIORITY_LOWEST = 1;
  
  public final static String  RECEIVE_EMAIL_SERVER_TYPE_POP3 = "pop3";
  public final static String  RECEIVE_EMAIL_SERVER_TYPE_IMAP = "imap";
  public final static String  RECEIVE_EMAIL_SERVER_TYPE_DOMINO = "domino";
  public final static String  RECEIVE_EMAIL_SERVER_TYPE_DOMINO_JOURNALING = "domino_journaling";

  public abstract List loadMailList(String host, String name, String password,String protocol) throws Exception ;    
  
  public abstract EmailFolder getFolder();	  
  
  //public abstract void analyseMultipart(EmailMessageImpl emailMessage, Object multipart);
  
  public abstract EmailMessage getMessageContent(HttpServletRequest request,String mailId,String mailServerType) throws ApplicationException;

  public abstract List loadAndProcessMailList(String host, String name, String password,String protocol) throws Exception ;
  
  //use for email archive to rule,not use yet
  public abstract EmailMessage getMessageContentNew(HttpServletRequest request,EmailMessage emailMessage,String mailServerType) throws ApplicationException;
  
  public abstract EmailMessageImpl analysemailEmailMessage(Message msg)throws Exception;
  
  public abstract void setEmailCharset(String charset)throws Exception;  
 /**
  * Method getMailByID()
  * 
  * @param mailList
  * @param strId
  * @return @throws
  *         Exception
  */
  public static EmailMessage getMailByID(List mailList, String strID)throws Exception {
    int id = 0;
    EmailMessage emailMessage = null;
    Iterator iter = mailList.iterator();
    while (iter.hasNext()) {
      EmailMessage emailMessageTmp = (EmailMessage) iter.next();
      if (emailMessageTmp.getID().intValue() == TextUtility.parseIntegerObj(strID).intValue()){
        emailMessage = emailMessageTmp;
        break;
      }    
    }
    return emailMessage;
  }
}